exports = @
$ = jQuery

TomatoBreak = exports.TomatoBreak

class MembershipController extends TomatoBreak.FormController

    constructor: ->

        super

        TomatoBreak[@modelName].bind 'error', (model, errors) => @showErrors errors

    submit: (event) ->

        event.preventDefault()

        model = new TomatoBreak[@modelName] @form.serializeForm()

        model.bind 'ajaxSuccess', (record, status, xhr) =>

            response = JSON.parse xhr.responseText if xhr.responseText

            if response?.errors?
                model.trigger 'error', model, response?.errors
            else
                exports.location = 'dashboard/#!/'

        model.save()

TomatoBreak.MembershipController = MembershipController